// DS(Displays)
//
// 多显示屏展示系统
//   Schemes: http, https
//   Version: 0.0.1
//   Contact: ender<xuender@gmail.com>
//   Host: localhost:8080
//   basePath: /api
//   Consumes:
//   - application/json
//   Produces:
//   - application/json
// swagger:meta
package main

import (
	"flag"
	"fmt"
	"log"
	"os"

	"gitee.com/xuender/ds/app"
	"github.com/gin-gonic/gin"
)

func main() {
	var cliDebug bool

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "ds (Displays) 多显示屏展示系统 v1.0.1\nUsage of ds:\n\nOptions:\n")
		flag.PrintDefaults()
	}

	flag.BoolVar(&cliDebug, "d", false, "调试模式")
	flag.Parse()

	if !cliDebug {
		gin.SetMode(gin.ReleaseMode)
	}
	// 默认配置文件
	if _, err := os.Stat(app.DSConfig); os.IsNotExist(err) {
		log.Printf("创建配置文件: %s", app.DSConfig)
		f, _ := os.Create(app.DSConfig)

		defer f.Close()
		_, _ = f.Write(app.MustAsset(fmt.Sprintf("assets/%s", app.DSConfig)))
	}
	// 背景图片
	const (
		files = "files"
		bg    = "bg.png"
	)

	if _, err := os.Stat(files); os.IsNotExist(err) {
		log.Printf("创建背景图片: %s/%s", files, bg)
		_ = os.Mkdir(files, os.ModePerm)
		f, _ := os.Create(fmt.Sprintf("%s/%s", files, bg))

		defer f.Close()
		_, _ = f.Write(app.MustAsset(fmt.Sprintf("assets/%s", bg)))
	}

	log.Println("启动DS...")

	a := app.InitializeApp()
	a.Run()
}
